import Overlay from 'ol/Overlay.js';
import { Injectable } from '@angular/core';
import { OVERLAY_KEY } from './map-data.service';

export interface OverlayOption {
    element?: any;
    positioning?: string;
    stopEvent?: boolean;
    offset?: number[];
    [key: string]: any;
}

@Injectable()
export class MapOverlayService {
    private _type = new Map([
        [
            OVERLAY_KEY.LOCATE_MARKER_OVERLAY,
            {
                element: null,
                positioning: 'top-left',
                stopEvent: true
                // offset: [0, 0]
                /* autoPan: true,
				autoPanAnimation: {
					duration: 250
				} */
            }
        ],
        [
            OVERLAY_KEY.ALERT_OVERLAY,
            {
                element: null,
                positioning: 'bottom-center',
                stopEvent: true,
                offset: [0, -10],
                autoPan: true,
                autoPanAnimation: {
                    duration: 250
                }
            }
        ],
        [
            OVERLAY_KEY.CLUSTER_FEATURES_OVERLAY,
            {
                element: null,
                positioning: 'top-center',
                stopEvent: true,
                offset: [0, 10],
                autoPan: true,
                autoPanAnimation: {
                    duration: 250
                }
            }
        ],
        [
            OVERLAY_KEY.INCIDENT_OVERLAY,
            {
                element: null,
                positioning: 'bottom-center',
                stopEvent: true,
                offset: [0, -10],
                autoPan: true,
                autoPanAnimation: {
                    duration: 250
                }
            }
        ],
        [
            OVERLAY_KEY.EQUIPMENT_OVERLAY,
            {
                element: null,
                positioning: 'bottom-center',
                stopEvent: true,
                offset: [0, -10],
                autoPan: true,
                autoPanAnimation: {
                    duration: 250
                }
            }
        ]
    ]);
    constructor() {}

    generaterOverlayByType(typeKey: OVERLAY_KEY, dom: any) {
        const option: OverlayOption = this._type.get(typeKey);
        option.element = dom;
        return new Overlay(option);
    }
}
